<?php
if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class Home extends CI_Controller {

	function __construct() {
		parent::__construct();
		$this->load->model('m_home');
	}

	function index() {
		$this->load->helper('options');
		// lebih jelasnya liat helper options
		$this->load->helper('id_date');
		// lebih jelasnya liat helper options

		$data['pengemudi'] = $this->m_home->get_pengemudi();
		$data['penumpang'] = $this->m_home->get_penumpang();
		$data['pengalaman'] = $this->m_home->get_pengalaman();
		$data['tentang'] = $this->m_home->get_konten_id('1');

		$this->layout->set_title(site_title() . ' &bull; ' . site_tagline());
		$this->layout->set_desc('Made with love by Raksa Abadi Informatika');
		$this->layout->theme('front','home/home',$data);
	}

	function konten() {
		$this->load->helper('options');
		// lebih jelasnya liat helper options
		$this->load->helper('id_date');
		// lebih jelasnya liat helper options

		$params = $this->uri->segment(2);
		$data['konten'] = $this->m_home->get_konten($params);
		$data['pengalaman'] = $this->m_home->get_pengalaman();
		$data['tentang'] = $this->m_home->get_konten_id('1');

		$this->layout->set_title(site_title() . ' &bull; ' . site_tagline());
		$this->layout->set_desc('Made with love by Raksa Abadi Informatika');
		$this->layout->theme('front','home/konten',$data);
	}

	function daftar() {
		$this->load->helper('options');
		// lebih jelasnya liat helper options
		$this->load->helper('id_date');
		// lebih jelasnya liat helper options

		$data['pengalaman'] = $this->m_home->get_pengalaman();
		$data['tentang'] = $this->m_home->get_konten_id('1');
		
		$this->layout->set_title(site_title() . ' &bull; ' . site_tagline());
		$this->layout->set_desc('Made with love by Raksa Abadi Informatika');
		$this->layout->theme('front','home/daftar',$data);
	}

	function form_pendaftaran() {
		$this->load->helper('options');
		// lebih jelasnya liat helper options
		$this->load->helper('id_date');
		// lebih jelasnya liat helper options

		$data['pengalaman'] = $this->m_home->get_pengalaman();
		$data['tentang'] = $this->m_home->get_konten_id('1');
		$data['kategori'] = $this->input->post('kategori');
		$data['kota'] = $this->m_home->get_kota();
		$data['jenis_kendaraan'] = $this->m_home->get_jenis_kendaraan();
		
		$this->layout->set_title(site_title() . ' &bull; ' . site_tagline());
		$this->layout->set_desc('Made with love by Raksa Abadi Informatika');
		$this->layout->theme('front','home/form-pendaftaran',$data);
	}

	function simpan_pendaftaran() {
		$this->load->helper('options');
		// lebih jelasnya liat helper options
		$this->load->helper('id_date');
		// lebih jelasnya liat helper options
		$kategori = $this->input->post('kategori');
		if($kategori == 'Pengendara'){
			$params_pengemudi = array(
				'id_driver' => 'STD0002',
				'nama_lengkap' => $this->input->post('nama_lengkap'),
				'nama_panggilan' => $this->input->post('nama_panggilan'),
				'id_asal' => $this->input->post('id_asal'),
				'id_tujuan' => '5',
				'jam_berangkat' => $this->input->post('jam'),
				'rute' => $this->input->post('rute'),
				'no_plat' => $this->input->post('plat'),
				'tgl_daftar' => date('Y-m-d h:i:s'),
				'password' => md5($this->input->post('password')),
				'koordinat' => $this->input->post('koordinat')
			);
			$params_kendaraan = array(
				'plat' => $this->input->post('plat'),
				'id_jenis' => $this->input->post('jenis_kendaraan'),
				'kapasitas' => $this->input->post('kapasitas')
			);
			$this->m_home->insert_kendaraan($params_kendaraan);
			$this->m_home->insert_pengemudi($params_pengemudi);
			$this->session->set_flashdata('pesan','Selamat Beragbung Bersama satutujuan.co.id');
		}else{
			$params_penumpang = array(
				'id_penumpang' => 'STP0002',
				'nama_lengkap' => $this->input->post('nama_lengkap'),
				'nama_panggilan' => $this->input->post('nama_panggilan'),
				'alamat' => $this->input->post('alamat'),
				'id_asal' => $this->input->post('id_asal'),
				'id_tujuan' => '5',
				'email' => $this->input->post('email'),
				'tgl_daftar' => date('Y-m-d h:i:s'),
				'password' => md5($this->input->post('password')),
				'koordinat' => $this->input->post('koordinat')
			);
			$this->m_home->insert_penumpang($params_penumpang);
			$this->session->set_flashdata('pesan','Selamat Beragbung Bersama satutujuan.co.id');
		}
		redirect('pesan');
	}

	function semua_pengalaman() {
		$this->load->helper('options');
		// lebih jelasnya liat helper options
		$this->load->helper('id_date');
		// lebih jelasnya liat helper options

		$data['pengalaman'] = $this->m_home->get_pengalaman();
		$data['tentang'] = $this->m_home->get_konten_id('1');
		
		$this->layout->set_title(site_title() . ' &bull; ' . site_tagline());
		$this->layout->set_desc('Made with love by Raksa Abadi Informatika');
		$this->layout->theme('front','home/pengalaman',$data);
	}

	function pesan() {
		$this->load->helper('options');
		// lebih jelasnya liat helper options
		$this->load->helper('id_date');
		// lebih jelasnya liat helper options

		$data['pengalaman'] = $this->m_home->get_pengalaman();
		$data['tentang'] = $this->m_home->get_konten_id('1');
		
		$this->layout->set_title(site_title() . ' &bull; ' . site_tagline());
		$this->layout->set_desc('Made with love by Raksa Abadi Informatika');
		$this->layout->theme('front','home/pesan',$data);
	}

	function login(){
		$username   = $this->input->post('username');
    	$password   = $this->input->post('password');
    	$kategori 	= $this->input->post('kategori');
		
    	$pass   = md5($password);
    	if($kategori == 'Pengemudi'){
    		$cek=$this->m_home->login_pengemudi($username,$pass);
    		if($cek!=false){
				if($this->m_home->cekStatusPengemudi($cek['id_driver'])){
	     			$data = array (
	          			'statusLogin' => 'yes',
						'id_driver'=>$cek['id_driver'],
						'nama'=>$cek['nama_panggilan'],
						'kategori'=>$kategori
	     			);
		      		$this->session->set_userdata($data);
		      		redirect('penumpang');
				}else{
					$this->session->set_flashdata('error_login', 'Username ini sudah tidak Aktif !');
          			redirect('home');
				}
      		}else{
				$this->session->set_flashdata('error_login', 'Username atau password anda salah !');
        		redirect('home');
      		}
    	}else{
    		$cek=$this->m_home->login_penumpang($username,$pass);
    		if($cek!=false){
				if($this->m_home->cekStatusPenumpang($cek['id_penumpang'])){
	     			$data = array (
	          			'statusLogin' => 'yes',
						'id_penumpang'=>$cek['id_penumpang'],
						'nama'=>$cek['nama_panggilan'],
						'kategori'=>$kategori
	     			);
		      		$this->session->set_userdata($data);
		      		redirect('permintaan-tumpangan');
				}else{
					$this->session->set_flashdata('error_login', 'Username ini sudah tidak Aktif !');
          			redirect('home');
				}
      		}else{
				$this->session->set_flashdata('error_login', 'Username atau password anda salah !');
        		redirect('home');
      		}
    	}	
	}

	function logOut(){
		$this->session->unset_userdata('statusLogin');
		$this->session->unset_userdata('id_driver');
		$this->session->unset_userdata('id_penumpang');
		$this->session->unset_userdata('kategori');
		$this->session->unset_userdata('nama_panggilan');
		$this->session->set_flashdata('error_login', 'Anda Sudah Log Out!');
		redirect('home');
	}

	function permintaan_tumpangan(){
		$this->load->helper('options');
		// lebih jelasnya liat helper options
		$this->load->helper('id_date');
		// lebih jelasnya liat helper options

		$data['pengalaman'] = $this->m_home->get_pengalaman();
		$data['tentang'] = $this->m_home->get_konten_id('1');
		$params = $this->session->userdata('id_penumpang');
		$data['list'] = $this->m_home->get_tumpangan($params);

		$this->layout->set_title(site_title() . ' &bull; ' . site_tagline());
		$this->layout->set_desc('Made with love by Raksa Abadi Informatika');
		$this->layout->theme('front','home/permintaan-tumpangan',$data);
	}
}

/* End of file welcome.php */

/* Location: ./application/controllers/home.php */
